package com.br.mvpexample;

import com.br.mvpexample.presenter.AskNamePresenter;
import com.br.mvpexample.views.IAskNameView;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class AskNameView extends Activity implements IAskNameView {
	/** Called when the activity is first created. */
	AskNamePresenter _presenter;

	public AskNameView() {
		_presenter = new AskNamePresenter(this);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_ask_name_view);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_ask_name_view, menu);
		return true;
	}

	@Override
	public void setDisplayedText(String text) {
		getShownLabel().setText(text);
	}

	public void submitClicked(View widget) {
		_presenter.EnterNameAndAge(getNameField().getText().toString(),
				Integer.parseInt(getAgeField().getText().toString()));
	}

	private EditText getNameField() {
		return (EditText) findViewById(R.id.name);
	}

	private EditText getAgeField() {
		return (EditText) findViewById(R.id.age);
	}

	private TextView getShownLabel() {
		return (TextView) findViewById(R.id.shown);
	}
}
